package com.fun;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.io.IOException;
import java.util.Map;

public class ConsolePipeline implements Pipeline {

    @Override
    public void process(ResultItems resultItems, Task task) {
        System.out.println("get page: " + resultItems.getRequest().getUrl());
        //遍历所有结果，输出到控制台，上面例子中的"author"、"name"、"readme"都是一个key，其结果则是对应的value
        for (Map.Entry<String, Object> entry : resultItems.getAll().entrySet()) {
            try {
                DownloadUtil.download(entry.getValue().toString(),"xxx.png","D:\\webmagic\\cach");
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println(entry.getKey() + "---------:\t" + entry.getValue());
        }
    }
}
